package com.dragon.client.controller.auth;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dragon.client.config.annotation.Log;
import com.dragon.common.model.Insert;
import com.dragon.common.model.ResponseData;
import com.dragon.logical.service.auth.IModifyLogService;
import com.dragon.repository.domain.dto.ModifyLogDTO;
import com.dragon.repository.domain.vo.ModifyLogVO;
import com.dragon.repository.entity.ModifyLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 修改日志 前端控制器
 * </p>
 *
 * @author sy
 * @since 2023-11-20
 */
@RestController
@RequestMapping("modifyLog")
@Api(tags = "历史记录")
public class ModifyLogController {

    @Autowired
    private IModifyLogService service;

    @GetMapping("modLogList")
    @ApiOperation(value = "历史记录列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", required = true, type = "int"),
            @ApiImplicitParam(name = "limit", value = "条数", required = true, type = "int"),
            @ApiImplicitParam(name = "streamType", value = "流程类型", required = true, type = "int"),
            @ApiImplicitParam(name = "correlationId", value = "主表id", required = true, type = "int")
    })
    public ResponseData<List<ModifyLogDTO>> modLogList(
            @RequestParam Integer page,
            @RequestParam Integer limit,
            @RequestParam Integer streamType,
            @RequestParam Integer correlationId){
        Page<ModifyLog> logPage =  service.modifyLogList(page, limit, streamType, correlationId);
        return ResponseData.success(ModifyLogDTO.convertList(logPage.getRecords()));
    }

    @PostMapping("add")
    @ApiOperation(value = "添加")
    @Log
    public ResponseData modifyLogAdd(@RequestBody @Validated(Insert.class) ModifyLogVO vo){
        service.modifyLogAdd(ModifyLogVO.convert(vo));
        return ResponseData.success();
    }

}
